package com.rzl.expense.quartz.task;


import com.rzl.expense.agent.DataAgentService;
import com.rzl.expense.common.utils.DateUtils;
import com.rzl.expense.expense.domain.TwrTowerBillBalance;
import com.rzl.expense.expense.domain.TwrTowerSiteCode;
import com.rzl.expense.expense.domain.twr.TwrHighRoom;
import com.rzl.expense.expense.service.ITwrTowerBillBalanceService;
import com.rzl.expense.expense.service.ITwrTowerSiteCodeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.time.LocalDate;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * 租赁费账单表
 *
 * @author admin
 * @date 2023/08/09
 */
@Slf4j
@Component("TwrTowerSiteCodeTask")  // 2.开启定时任务
public class TwrTowerSiteCodeTask {
    @Autowired
    private DataAgentService dataAgentService;

    @Autowired
    private ITwrTowerSiteCodeService twrTowerSiteCodeService;


    /**
     * 集团用户同步
     */
    public void run(String date) {


        log.info("获取集团用户数据【" + date + "】月数据");
        List<TwrTowerSiteCode> list = (List<TwrTowerSiteCode>) dataAgentService.getData(RuleSqlAdapter.getTowerSiteCode(date), TwrTowerSiteCode.class);

        if (!Objects.isNull(list)) {
            int size = list.size();
            // limit起始位置
            int startIndex = 0;
            // limit大小
            int limit = 1000;
            do {
                try {
                    List<TwrTowerSiteCode> twrHighTowers = list.stream().skip(startIndex).limit(limit).collect(Collectors.toList());
                    if (!Objects.isNull(twrHighTowers)) {
                        twrTowerSiteCodeService.batchTwrTowerSiteCode(twrHighTowers);
                        size = twrHighTowers.size();
                        startIndex = startIndex + limit;
                    }
                } catch (Exception e) {
                }

            } while (size >= limit);
        }
        log.info("数据总数统计");
    }
}
